package com.xiaoyu.client.adapter.seek;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xiaoyu.client.R;
import com.xiaoyu.client.model.seek.SeekReplyParam;
import com.xiaoyu.commonlib.utils.CCircleImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jk on 2018/10/29.
 */
public class ThankedAdapter extends BaseAdapter {
    private Context mContext;
    private List<SeekReplyParam> mList = new ArrayList<>();
    private List<String> selectList = new ArrayList<>();

    public ThankedAdapter(Context mContext, List<SeekReplyParam> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public SeekReplyParam getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder {
        RelativeLayout rootLayout;
        CCircleImageView photoImg;
        TextView nameTxt;
        TextView suggestTxt;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_seek_over_thanked, parent, false);
            holder = new ViewHolder();
            holder.rootLayout = convertView.findViewById(R.id.item_seek_over_thanked_root);
            holder.photoImg = convertView.findViewById(R.id.item_seek_thanked_person_photo);
            holder.nameTxt = convertView.findViewById(R.id.item_seek_thanked_person_name);
            holder.suggestTxt = convertView.findViewById(R.id.item_seek_thanked_person_suggest);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (selectList.indexOf(getItem(position).getUserid()) == -1) {
            holder.rootLayout.setSelected(false);
        } else {
            holder.rootLayout.setSelected(true);
        }

        Glide.with(mContext).load(getItem(position).getUserphoto()).into(holder.photoImg);
        holder.nameTxt.setText(getItem(position).getNickname());
        String content = getItem(position).getSeekreplycontent();
        holder.suggestTxt.setText(content);
        return convertView;
    }

    public void setSelectList(List<String> selectList) {
        this.selectList = selectList;
        this.notifyDataSetChanged();
    }
}
